function request(url) {
    return new Promise((res, rej) => {
        setTimeout(() => {
            res(url)
        }, 1000)
    })
}
// request('aaa').then(res => {
//     return request(res + 'bbb')
// }).then(res => {
//     return request(res + 'ccc')
// }).then(res => {
//     console.log(res);
// }).catch(err => {
//     console.log(err);
// })

function* getData() {
    const a = yield request('aaa')
    const b = yield request(a + 'bbb')
    const c = yield request(b + 'ccc')
    console.log(c);
}
// const g1 = getData()
// g1.next().value.then(res => {
//     g1.next(res).value.then(res => {
//         g1.next(res).value.then(res => {
//             g1.next(res)
//         })
//     })
// })

// https://www.npmjs.com/package/co
function execGenerator(genFunc) {
    const g1 = genFunc()
    function exec(res) {
        const result = g1.next(res)
        if (!result.done) {
            result.value.then(exec)
        }
    }
    exec()
}
execGenerator(getData)

// es2017
async function getDataAsync() {
    const a = await request('aaa')
    const b = await request(a + 'bbb')
    const c = await request(b + 'ccc')
    console.log(c);
}
getDataAsync()